package servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class TestServlet extends HttpServlet{
	
	public TestServlet() {
		
		System.out.println("TestSErvelt construct....");
	}
	@Override
	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		super.init(config);
		String encoding=config.getInitParameter("encoding");
		System.out.println("init...."+encoding);
	}
	@Override
	public void destroy() {
		// TODO Auto-generated method stub
		super.destroy();
		System.out.println("destroy....");
	}
	@Override
	protected  void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String s=this.getServletContext().getInitParameter("encoding");
		System.out.println(s);
		
//		this.getServletConfig();
//		this.getServletContext().setAttribute("cart1", "");
//		String item=req.getParameter("item");
//		HttpSession sen=req.getSession();
//		
//		List<String> cart=(List<String>)sen.getAttribute("cart");
//		if(cart==null){
//			cart=new ArrayList<String>();
//			sen.setAttribute("cart", cart);
//		}
//		cart.add(item);
//		req.getRequestDispatcher("/target").forward(req, resp);
	}
	@Override
	protected  void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException{
		doGet(req, resp);
	}
}
